#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string countAndSay(int n) {
        string begin("1");
        while (--n)
        {
            string next;
            int count = 0;
            for (int i = 0; i < begin.size(); i++)
            {
                count = 1;
                while (i + 1 < begin.size() && begin[i] == begin[i + 1])
                {
                    count++;
                    i++;
                }
                string num = to_string(count);
                next += num;
                next += begin[i];
            }
            begin = next;
        }
        return begin;
    }
};